using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PBR.Controls
{
    public partial class MaterialProperties : UserControl
    {
        private Scene scene;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="scene"></param>
        public MaterialProperties(Scene scene)
        {
            InitializeComponent();

            this.scene = scene;            
        }

        /// <summary>
        /// 
        /// </summary>
        public void InitSegment()
        {
            Material mat = scene.SelectedMat;

            selectedMatLabel.Text = mat.Name;

            diffuseScrollBar.Value = (int)(scene.SelectedMat.DiffuseCoef * 100);
            diffuseNumericUpDown.Value = (int)(scene.SelectedMat.DiffuseCoef * 100);

            specularScrollBar.Value = (int)(scene.SelectedMat.SpecularCoef * 100);
            specularNumericUpDown.Value = (int)(scene.SelectedMat.SpecularCoef * 100);

            ambientScrollBar.Value = (int)(scene.SelectedMat.AmbientCoef * 100);
            ambientNumericUpDown.Value = (int)(scene.SelectedMat.AmbientCoef * 100);

            shininessScrollBar.Value = (int)(scene.SelectedMat.Shininess * 100);
            shininessNumericUpDown.Value = (int)(scene.SelectedMat.Shininess * 100);

            vScaleScrollBar.Value = (int)(scene.SelectedMat.VScale * 100);
            vScaleNumericUpDown.Value = (int)(scene.SelectedMat.VScale * 100);
        }

        private void MaterialProperties_Load(object sender, EventArgs e)
        {
        }

        private void diffuseScrollBar_Scroll(object sender, ScrollEventArgs e)
        {

        }

        #region Diffuse

        private void diffuseScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.DiffuseCoef = (float)diffuseScrollBar.Value / 100.0f;
            diffuseNumericUpDown.Value = diffuseScrollBar.Value;
        }

        private void diffuseNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.DiffuseCoef = (float)diffuseNumericUpDown.Value / 100.0f;
            diffuseScrollBar.Value = (int)diffuseNumericUpDown.Value;
        }

        #endregion

        #region Specular

        private void specularScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.SpecularCoef = (float)specularScrollBar.Value / 100.0f;
            specularNumericUpDown.Value = specularScrollBar.Value;
        }

        private void specularNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.SpecularCoef = (float)specularNumericUpDown.Value / 100.0f;
            specularScrollBar.Value = (int)specularNumericUpDown.Value;
        }

        #endregion

        #region Ambient

        private void ambientScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.AmbientCoef = (float)ambientScrollBar.Value / 100.0f;
            ambientNumericUpDown.Value = ambientScrollBar.Value;
        }

        private void ambientNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.AmbientCoef = (float)ambientNumericUpDown.Value / 100.0f;
            ambientScrollBar.Value = (int)ambientNumericUpDown.Value;
        }

        #endregion

        #region Shininess

        private void shininessScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Shininess = (float)shininessScrollBar.Value / 100.0f;
            shininessNumericUpDown.Value = shininessScrollBar.Value;
        }

        private void shininessNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Shininess = (float)shininessNumericUpDown.Value / 100.0f;
            shininessScrollBar.Value = (int)shininessNumericUpDown.Value;
        }

        #endregion

        #region vScale

        private void vScaleScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.VScale = (float)vScaleScrollBar.Value / 100.0f;
            vScaleNumericUpDown.Value = vScaleScrollBar.Value;
        }

        private void vScaleNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.VScale = (float)vScaleNumericUpDown.Value / 100.0f;
            vScaleScrollBar.Value = (int)vScaleNumericUpDown.Value;
        }

        #endregion

    }
}
